package com.example.recyclerviewtest204sy;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;//控件
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;//recycleview适配器

    private List<ArticleBean> list=null;//缓存数据

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecycleView();
    }
    //初始化recyclerview
    private void initRecycleView() {
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        //创建默认线性布局
        layoutManager=new LinearLayoutManager(this);
        //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        list=getData();
        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);

    }
    private List<ArticleBean> getData()
    {
        List<ArticleBean> list=new ArrayList<ArticleBean>();

        ArticleBean articleBean;
        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("1");
        articleBean.setDescription("a");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f1);
        list.add( articleBean);


        articleBean=new ArticleBean();
        articleBean.setArticleId(2);
        articleBean.setTitle("2");
        articleBean.setDescription("b");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f2);
        list.add( articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(3);
        articleBean.setTitle("3");
        articleBean.setDescription("c");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f3);
        list.add( articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("4");
        articleBean.setDescription("d");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f4);
        list.add( articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("5");
        articleBean.setDescription("e");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f5);
        list.add( articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("6");
        articleBean.setDescription("f");
        articleBean.setTime("2017-4-18");
        articleBean.setImgid(R.drawable.f6);
        list.add( articleBean);
        return list;
    }




}